package com.heima.search.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.search.dtos.HistorySearchDto;
import com.heima.search.pojos.ApUserSearch;
import com.heima.search.service.UserSearchService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author brianxia
 * @version 1.0
 * @date 2022-09-20 16:28
 */
@RestController
@RequestMapping("/api/v1/history")
public class HistoryController {
    @Autowired
    private UserSearchService userSearchService;

    @PostMapping("/load")
    public ResponseResult load(){

        List<ApUserSearch> list = userSearchService.load();
        return  ResponseResult.okResult(list);
    }

    @PostMapping("/del")
    public ResponseResult del(@RequestBody HistorySearchDto dto){
        if(StringUtils.isBlank(dto.getId())){
            //判断id是否为空
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }

        userSearchService.delete(dto.getId());

        return ResponseResult.okResult(null);
    }
}
